package com.jci.vsd.adapter.reim;

/**
 * Created by liqing on 18/6/28.
 */

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jci.vsd.R;
import com.jci.vsd.bean.reim.MyReimDetailBean;
import com.jci.vsd.constant.MySpEdit;
import com.jci.vsd.utils.Loger;

import java.util.List;

/**
 * Created by liqing on 18/3/20.
 */

public class ApprovalDetailRecycleAdapter extends RecyclerView.Adapter<ApprovalDetailRecycleAdapter.MyViewHolder> {

    private Context context;
    private List<MyReimDetailBean.CostsBean> list;
    private LayoutInflater inflater;

    public ApprovalDetailRecycleAdapter(Context context, List<MyReimDetailBean.CostsBean> list) {
        this.context = context;
        this.list = list;
        this.inflater = LayoutInflater.from(this.context);
    }


    public static interface OnItemClickListener {
        void OnItemClick(View view, int pos);

        void onPicCLick(View view, int pos);

    }

    //    public static interface OnItemClickListener {
//        void OnItemClick(View view, int pos);
//    }
    public ApprovalDetailRecycleAdapter.OnItemClickListener listener;

    public void setOnItemClickListener(ApprovalDetailRecycleAdapter.OnItemClickListener listener) {
        this.listener = listener;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder myViewHolder = null;
        myViewHolder = new MyViewHolder(inflater.inflate(R.layout.item_approval_detail_new, parent, false));

        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        final MyReimDetailBean.CostsBean bean = list.get(position);
        if (bean != null) {

                Loger.e("---fee"+bean.getAmount()+" name"+MySpEdit.getInstance().getRealName());
                holder.tvFee.setText("¥"+bean.getAmount());
                holder.tvName.setText( MySpEdit.getInstance().getRealName());
                holder.tvExpenseType.setText(bean.getName());

                Glide.with(context)
                        .load(bean.getUrl())
                        .into(holder.ivPic);

              //  holder.rlItem.setTag(position);
                holder.ivFrame.setTag(position);

                holder.ivFrame.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (listener != null) {
                            listener.onPicCLick(view, (int) view.getTag());
                        }
                    }
                });



        }

    }

    @Override
    public int getItemCount() {

        if (list == null)
            return 0;
        return list.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {

        TextView tvFee;
        TextView tvDate;
        TextView tvName;
        TextView tvExpenseType;
        ImageView ivPic;
        View view;
        FrameLayout ivFrame;

        public MyViewHolder(View view) {
            super(view);
            //fee
            tvFee = (TextView) view.findViewById(R.id.tv_money);
            //data
            tvDate = (TextView) view.findViewById(R.id.tv_expense_time);
            //审批人
            tvName = (TextView) view.findViewById(R.id.tv_title);
            //报销单 pic
            ivPic = (ImageView) view.findViewById(R.id.iv_expense_item_pic);

            tvExpenseType = (TextView) view.findViewById(R.id.tv_expense_type);
//            tvExplain = (TextView) view.findViewById(R.id.tv_explain);
//            rlItem = (RelativeLayout) view.findViewById(R.id.rl_expense_item);

            ivFrame = (FrameLayout) view.findViewById(R.id.iv_frame);
            this.view = view;
        }
    }
}
